﻿@model IEnumerable<AdventureWorks.Entities.Customer>
@using PagedList;
@using PagedList.Mvc;
@using AdventureWorks.Entities;

@{
    ViewBag.Title = "Index";
	int pageIndex = ViewBag.PageIndex;
	int pageSize = ViewBag.PageSize;
}
<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />
<h2>Customers</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<fieldset>
	<legend>Filter</legend>
	@using (Html.BeginForm())
	{
		<p>
			Find by name: @Html.TextBox("searchString", ViewBag.CurrentFilter as String) &nbsp;
			<input type="submit" value="Search" />
		</p>
	}
</fieldset>
<table>
    <tr>
        <th>@Html.ActionLink("Name", "Index", new { sortOrder = ViewBag.NameSortParam, currentFilter = ViewBag.CurrentFilter })</th>
        <th>@Html.ActionLink("Company Name", "Index", new { sortOrder = ViewBag.CompanySortParam, currentFilter = ViewBag.CurrentFilter })</th>
        <th>Sales Person</th>
        <th>Email Address</th>
        <th>Phone</th>
        <th>@Html.ActionLink("Modif Date", "Index", new { sortOrder = ViewBag.DateSortParam, currentFilter = ViewBag.CurrentFilter })</th>
        <th></th>
    </tr>

@foreach (var item in Model.ToPagedList<Customer>(pageIndex, pageSize))
{
    <tr>
        <td>@Html.DisplayFor(modelItem => item.FullName)</td>
        <td>@Html.DisplayFor(modelItem => item.CompanyName)</td>
        <td>@Html.DisplayFor(modelItem => item.SalesPerson)</td>
        <td>@Html.DisplayFor(modelItem => item.EmailAddress)</td>
        <td>@Html.DisplayFor(modelItem => item.Phone)</td>
        <td>@Html.DisplayFor(modelItem => item.ModifiedDate)</td>
        <td align="center">
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}
	<tr>
		<td colspan="7">
			@Html.PagedListPager(
	(IPagedList)Model.ToPagedList(pageIndex, pageSize),
	page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }),
	new PagedListRenderOptions { 
	                           	LinkToFirstPageFormat = "<< First",
	                           	LinkToPreviousPageFormat = "< Prev",
	                           	LinkToNextPageFormat = "> Next",
	                           	LinkToLastPageFormat = ">> Last",
	                           	MaximumPageNumbersToDisplay = 5
	                           })
		</td>
	</tr>
</table>
